# import tools.db_demo

# a=tools.db_demo.DB()
# data=a.query('select * from user')
# print(data)
# test=tools.db_demo.mytest()
# print(test)
# print(tools.db_demo.name)


# from tools.db_demo import DB,mytest,name
# print(name)
# print(mytest())
# a=DB()
# a.query('select * from user')

# import tools.db_demo as db
# print(db.name)
# print(db.mytest())

from tools.db_demo import db
# from tools import db_demo as m
# a=m.DB().query('select * from user')
# print(a)
sql1 = "select name,author,count from book where status!='-1' and count !='0'"
print(db.query(sql1))
a=db.query("select id from book where name='笨办法学Python'")
b=a[0]
print(a)

# sql = f"select id,count,status from book where name='笨办法学Python'"
# a = db.query(sql)  # 查看数据库中该书的库存和是否为禁书，书的id
# b_id = a[0]['id']
# print(a)
# print(b_id)

# booked = db.query(f"select bookid,name,borrow_time,return_time from user inner join records on user.id=user_id inner join book on book.id = records.bookid where username='feiy' and return_time is null")  # 已经借过的书
# print(booked)


# books = db.query("select id,name,author,count from book where count>=1 and `status`='0'")  # 有库存且允许借阅的书
# booked = db.query(f"select bookid,name from user inner join records on user.id=user_id inner join book on book.id = records.bookid where return_time is null and username='{username}'")  # 借了没还
# print(books)
# print(booked)
# sql2 = f"insert records (id,user_id,bookid,borrow_time) values('{r_id}','{u_id}','{b_id}','{shijian}')"
# sql3 = f"update book set count=count-1 where id='{b_id}'"
# a=[i['name'] for i in books]
# b=[i['name'] for i in booked]
# if js in a and js not in b:

